package de.tabuma.pm.projectnavigation.entity;

import java.util.*;

/**
 *
 * @author alefen
 */
public class ProjectNavigationWrapper extends ProjectNavigation {

    public ProjectNavigationWrapper(ProjectNavigation pn, int ebene) {
        this.projectId = pn.getProjectId();
        this.navigationId = pn.getNavigationId();
        this.navMode = pn.getNavMode();
        this.subElements = new ArrayList<ProjectNavigationWrapper>();
        this.ebene = ebene;
        this.id = pn.getId();
        this.name = pn.getName();
        this.order = pn.getOrder();
        this.functionId = pn.getFunctionId();
        this.functionTypeId = pn.getFunctionTypeId();
    }


    List<ProjectNavigationWrapper> subElements;
    public List<ProjectNavigationWrapper> getSubElements() {
        return this.subElements;
    }

    int ebene;
    public int getEbene() {
        return ebene;
    }


    /**
     * @param pnList
     * @return Elements that were not included
     */
    public List<ProjectNavigation> loadSubElement(List<ProjectNavigation> pnList) {
        if(pnList.size()==0) {
            return pnList;
        }
        for(int i=0;i<pnList.size();i++) {
            if(this.getId()==pnList.get(i).getNavigationId()) {
                subElements.add(new ProjectNavigationWrapper(pnList.get(i), this.ebene+1));
                pnList.remove(i);
                i--;
            }
        }

        for(int i=0;i<this.subElements.size();i++) {
            pnList = this.subElements.get(i).loadSubElement(pnList);
        }

        return pnList;
    }
}
